<?php


/**
 * 
 * @since 16.04.12 22:57
 * @author Arsen Abdusalamov
 */
class Breadcrumbs extends CBreadcrumbs {
	
	/**
	 * @since 16.04.12 22:57
	 * @author Arsen Abdusalamov
	 */
	public function run() {
		
		if(empty($this->links)) {
			return;
		}
		echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
		$links=array();
		
		if($this->homeLink===null) {
			$links[]=CHtml::link(Yii::t('zii','Home'),Yii::app()->homeUrl);
		} else if($this->homeLink!==false) {
			$links[]=$this->homeLink;
		}
		
		$separator = '<span class="divider">' . CHtml::encode( $this->separator ) .'</span>';
		$isUl = stripos( $this->tagName, 'ul' ) === 0;
		if ( $isUl ) {
			$separator .= '</li><li>';
		}
		foreach($this->links as $label=>$url) {
			$link = is_string($label) || is_array($url)
				? CHtml::link($this->encodeLabel ? CHtml::encode($label) : $label, $url)
				: ($this->encodeLabel ? CHtml::encode($url) : $url);
		}
		
		$linksHtml = implode($separator,$links);
		
		echo $isUl 
			? '<li>' . $linksHtml . '</li>' 
			: $linksHtml;
		
		echo CHtml::closeTag($this->tagName);
	}

}